<?php

include('config.inc.php');
include_once('functions.inc.php');
include_once('wikipedia.php');

$resource_local = @mysql_connect($db_config['db_host'], $db_config['db_username'], $db_config['db_password'])
	or die(mysql_error());

ini_set('default_charset', 'UTF-8');

mysql_set_charset('utf8', $resource_local);

mysql_select_db($db_config['db_name'], $resource_local);

$term = null;

$resource = mysql_log("SELECT search, redirect FROM metrics LEFT JOIN redirect ON metrics.search = redirects.redirect;");

while (true)
{
	if (!isset($term))
		list($term) = mysql_fetch_array(mysql_log("SELECT article FROM articles WHERE id IN (SELECT term2 FROM relationships WHERE term2 NOT IN (SELECT term1 FROM relationships) AND term1 = (SELECT id FROM articles WHERE article = '$article'));"));

	echo "TERM: $term\n";
	print_r(get_related_terms($term, $cache_hits, true));

	$term = null;
}
